package data.handle;

import java.util.LinkedList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;

public class SelectResult implements Runnable{
    private CountDownLatch countDownLatch;
    private LinkedBlockingQueue<Result> results;
    private LineItemHandle lineItemHandle;
    private byte brandIndex;
    private double quantity;

    public SelectResult(LineItemHandle lineItemHandle, byte brandIndex, double quantity, LinkedBlockingQueue<Result> results, CountDownLatch downLatch){
        this.countDownLatch = downLatch;
        this.results = results;
        this.lineItemHandle = lineItemHandle;
        this.brandIndex = brandIndex;
        this.quantity = quantity;
    }
    @Override
    public void run() {
        LinkedList<LineItemHandle.Node> select = lineItemHandle.select(brandIndex, quantity);

        for (LineItemHandle.Node node : select) {
            Result result = new Result(node.getPartKey(), node.getPriceSum());
            results.add(result);
//            System.out.println("brand : "+ brandIndex +" result Partkey : "+result.getPartKey());
        }
        countDownLatch.countDown();
    }
}
